package com.shijiwei.trip.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.shijiwei.trip.bean.RecommendBean.Elements;
import com.shijiwei.trip.bean.RecommendBean.ElementsBean;

import java.util.List;

/**
 * Created by sjw on 2015/12/9.
 */
public class RecommendAdapter extends BaseAdapter{

    private final int TYPE_1 = 0;
    private final int TYPE_2 = 1;
    private final int TYPE_3 = 2;
    private final int TYPE_4 = 3;
    private final int TYPE_5 = 4;
    private final int TYPE_6 = 5;
    private final int TYPE_7 = 6;
    private final int TYPE_COUNT = 7;

    private List<ElementsBean> list;
    private LayoutInflater inflater;

    public RecommendAdapter(Context context,List<ElementsBean> list) {
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return list == null ? 0 : position;
    }

    @Override
    public int getItemViewType(int position) {
        int type = list.get(position).getType();

        if (type == 1){
            return TYPE_1;
        }else if (type == 11){
            return TYPE_2;
        }else if (type == 10){
            return TYPE_3;
        }else if (type == 9){
            return TYPE_4;
        }else if (type == 7){
            return TYPE_5;
        }else if (type == 12){
            return TYPE_6;
        }else if (type == 4){
            return TYPE_7;
        }
        return super.getItemViewType(position);
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_COUNT;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder1  holder1 = null;
        ViewHolder2  holder2 = null;
        ViewHolder3  holder3 = null;
        ViewHolder4  holder4 = null;
        ViewHolder5  holder5 = null;
        ViewHolder6  holder6 = null;
        ViewHolder7  holder7 = null;
        if (convertView == null){
            switch (getItemViewType(position)){
                case TYPE_1:
//                    convertView = inflater.inflate()
                    holder1 = new ViewHolder1();
                    convertView.setTag(holder1);
                    break;
                case TYPE_2:
                    holder2 = new ViewHolder2();
                    convertView.setTag(holder2);
                    break;
                case TYPE_3:
                    holder3 = new ViewHolder3();
                    convertView.setTag(holder3);
                    break;
                case TYPE_4:
                    holder4 = new ViewHolder4();
                    convertView.setTag(holder4);
                    break;
                case TYPE_5:
                    holder5 = new ViewHolder5();
                    convertView.setTag(holder5);
                    break;
                case TYPE_6:
                    holder6 = new ViewHolder6();
                    convertView.setTag(holder6);
                    break;
                case TYPE_7:
                    holder7 = new ViewHolder7();
                    convertView.setTag(holder7);
                    break;

            }
        }else {
            switch (getItemViewType(position)){
                case TYPE_1:
                    holder1 = (ViewHolder1) convertView.getTag();
                    break;
                case TYPE_2:
                    holder2 = (ViewHolder2) convertView.getTag();
                    break;
                case TYPE_3:
                    holder3 = (ViewHolder3) convertView.getTag();
                    break;
                case TYPE_4:
                    holder4 = (ViewHolder4) convertView.getTag();
                    break;
                case TYPE_5:
                    holder5 = (ViewHolder5) convertView.getTag();
                    break;
                case TYPE_6:
                    holder6 = (ViewHolder6) convertView.getTag();
                    break;
                case TYPE_7:
                    holder7 = (ViewHolder7) convertView.getTag();
                    break;
            }
        }

        switch (getItemViewType(position)){ //赋值
            case TYPE_1:
                break;
            case TYPE_2:
                break;
            case TYPE_3:
                break;
            case TYPE_4:
                break;
            case TYPE_5:
                break;
            case TYPE_6:
                break;
            case TYPE_7:
                break;

        }
        return convertView;
    }

    class ViewHolder1{

    }
    class ViewHolder2{

    }
    class ViewHolder3{

    }

    class ViewHolder4{

    }
    class ViewHolder5{

    }
    class ViewHolder6{

    }
    class ViewHolder7{

    }
}
